home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / emul / cp4 / c2p_src / c2p_card.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  6KB  |  223 lines

  1. /* :ts=4                            c2p_card.c
  2.  *
  3.  *    cp4 - Commodore C+4 emulator
  4.  *    Copyright (C) 1998 Gáti Gergely
  5.  *
  6.  *    This program is free software; you can redistribute it and/or modify
  7.  *    it under the terms of the GNU General Public License as published by
  8.  *    the Free Software Foundation; either version 2 of the License, or
  9.  *    (at your option) any later version.
  10.  *
  11.  *    This program is distributed in the hope that it will be useful,
  12.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *    GNU General Public License for more details.
  15.  *
  16.  *    You should have received a copy of the GNU General Public License
  17.  *    along with this program; if not, write to the Free Software Foundation,
  18.  *    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  *
  20.  *    e-mail: gatig@dragon.klte.hu
  21.  */
  22. #include <proto/graphics.h>
  23. #include <proto/exec.h>
  24. #include <proto/intuition.h>
  25. #include <exec/memory.h>
  26.  
  27. #include "cp4_ver.h"
  28.  
  29. #define C2P_VERSION        "1"
  30. #define C2P_REVISION    "2"
  31. #define C2P_AUTHOR        "gega <Gáti Gergely>"
  32. #define C2P_NAME        "Card"
  33. #define C2P_BUFFERING    3
  34. #define C2P_DATE        DATE
  35. #define C2P_LOCALIZE
  36.  
  37. #include "c2p_module.c"
  38. #include "c2p_card_palette.c"
  39.  
  40.  
  41. struct GfxBase *GfxBase=NULL;
  42. struct IntuitionBase *IntuitionBase=NULL;
  43. static struct BitMap *bmapwpx;
  44. static struct RastPort *tmpraswpx;
  45. static struct RastPort *raswpx;
  46. static struct ScreenBuffer *scrb[3];
  47. static UWORD *nopointer=NULL;
  48. static struct Screen *scr=NULL;
  49. static struct Window *win=NULL;
  50. static int winsleeped=0;
  51. static struct Requester InvisibleRequester;
  52.  
  53. #define MSG_INFO 0
  54. #define MSG_NOSCRMODE 1
  55. #define MSG_NOGFX 2
  56. #define MSG_NOINTUI 3
  57. #define MSG_NOSCR 4
  58. #define MSG_NOWIN 5
  59. #define MSG_NOMEM 6
  60.  
  61. static char *defstr[]={
  62.     "This is a driver for graphics cards. It's working on AGA too, but it's use the WritePixelArray8() function, and it's deadly slow on AGA.",
  63.     "No ScreenMode Specified",
  64.     "Can't open graphics.library V39",
  65.     "Can't open intuition.library V39",
  66.     "Can't open Screen",
  67.     "Can't open Window",
  68.     "Not enough memory",
  69.     NULL
  70. };
  71.  
  72.  
  73. char *SAVEDS minfo(void) {
  74. static char in[1024];
  75.     char *s;
  76.     c2p_OpenCatalog(defstr);
  77.     s=STR(MSG_INFO);
  78.     c2p_strncpy(in,s,1023);
  79.     c2p_CloseCatalog();
  80.     return(in);
  81. }
  82.  
  83. char *SAVEDS minit(ULONG scrmode, ULONG overscan, unsigned char *linedeltatab) {
  84.     int planes=8;
  85.  
  86.     c2p_OpenCatalog(defstr);
  87.  
  88.     if(scrmode==~0) return(STR(MSG_NOSCRMODE));
  89.  
  90.     /* Allocate mem for nopointer
  91.      */
  92.     if(NULL==(nopointer=AllocVec(24,MEMF_CHIP|MEMF_CLEAR))) return(STR(MSG_NOMEM));
  93.  
  94.     if((GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",39))==NULL) return(STR(MSG_NOGFX));
  95.     if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",39))) return(STR(MSG_NOINTUI));
  96.  
  97.     /* Allocate bitmaps
  98.      */
  99.     bmapwpx=AllocBitMap(SCRWIDTH,1,8,BMF_CLEAR,NULL);
  100.     if(bmapwpx==NULL) return(STR(MSG_NOMEM));
  101.     tmpraswpx=AllocVec(sizeof(struct RastPort),MEMF_ANY);
  102.     if(tmpraswpx==NULL) return(STR(MSG_NOMEM));
  103.     InitRastPort(tmpraswpx);
  104.     tmpraswpx->BitMap=bmapwpx;
  105.     raswpx=AllocVec(sizeof(struct RastPort),MEMF_ANY);
  106.     if(raswpx==NULL) return(STR(MSG_NOMEM));
  107.     InitRastPort(raswpx);
  108.  
  109.     /* Open Screen
  110.      */
  111.     if(NULL==(scr=OpenScreenTags(NULL,
  112.                 SA_DisplayID, scrmode,
  113.                 SA_Depth, planes,
  114.                 SA_ShowTitle,FALSE,
  115.                 SA_Quiet, TRUE,
  116.                    SA_Width, SCRWIDTH,
  117.                    SA_Height, SCRHEIGHT,
  118.                    SA_Behind, TRUE,
  119.                    SA_Colors32, (ULONG)Palette,
  120.                 SA_Overscan, overscan,
  121.                 SA_Type, CUSTOMSCREEN,
  122.                 TAG_DONE,0L )))
  123.         return(STR(MSG_NOSCR));
  124.     vec.c2p_Scr=scr;
  125.  
  126.     /* Open window
  127.      */
  128.     if((win=(struct Window *)OpenWindowTags(NULL,
  129.                 WA_NoCareRefresh, TRUE,
  130.                 WA_Activate, TRUE,
  131.                 WA_Borderless, TRUE,
  132.                 WA_Backdrop, TRUE,
  133.                 WA_CustomScreen, (ULONG)scr,
  134.                 WA_RMBTrap, TRUE,
  135.                 WA_RptQueue, 25,
  136.                 TAG_DONE,0L ))==NULL)
  137.         return(STR(MSG_NOWIN));
  138.     vec.c2p_Win=win;
  139.     winsleeped=0;
  140.  
  141.     /* set nopointer
  142.      */
  143.     SetPointer(win,nopointer,1,16,0,0);
  144.  
  145.     /* Allocate screen buffers
  146.      */
  147.     scrb[0]=AllocScreenBuffer(scr,NULL,NULL);
  148.     scrb[1]=AllocScreenBuffer(scr,NULL,NULL);
  149.     scrb[2]=AllocScreenBuffer(scr,NULL,NULL);
  150.     if(scrb[0]==NULL||scrb[1]==NULL||scrb[2]==NULL) return(STR(MSG_NOMEM));
  151.     scrb[0]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  152.     scrb[0]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  153.     scrb[1]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  154.     scrb[1]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  155.     scrb[2]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
  156.     scrb[2]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=NULL;
  157.     return(NULL);
  158. } // init
  159.  
  160.  
  161. void SAVEDS mfree(void) {
  162.     mawake();
  163.     if(GfxBase) WaitTOF();
  164.     if(scrb[0]) { FreeScreenBuffer(scr,scrb[0]); scrb[0]=NULL; }
  165.     if(scrb[1]) { FreeScreenBuffer(scr,scrb[1]); scrb[1]=NULL; }
  166.     if(scrb[2]) { FreeScreenBuffer(scr,scrb[2]); scrb[2]=NULL; }
  167.     if(win) ClearPointer(win);
  168.     if(nopointer) { FreeVec(nopointer); nopointer=NULL; }
  169.     if(win) { CloseWindow(win); win=NULL; }
  170.     vec.c2p_Win=NULL;
  171.     if(scr) { CloseScreen(scr); scr=NULL; }
  172.     vec.c2p_Scr=NULL;
  173.     if(bmapwpx) FreeBitMap(bmapwpx);
  174.     if(tmpraswpx) FreeVec(tmpraswpx);
  175.     if(raswpx) FreeVec(raswpx);
  176.     if(GfxBase) CloseLibrary((struct Library *)GfxBase);
  177.     if(IntuitionBase) { CloseLibrary((struct Library *)IntuitionBase); IntuitionBase=NULL; }
  178.     c2p_CloseCatalog();
  179. } // free
  180.  
  181.  
  182. int SAVEDS mdo(unsigned char *chunky,unsigned char *delta,int numscreen) {
  183.     raswpx->BitMap=scrb[numscreen]->sb_BitMap;
  184.     WritePixelArray8(raswpx,0,0,SCRWIDTH-1,SCRHEIGHT-1,chunky,tmpraswpx);
  185.     ChangeScreenBuffer(scr,scrb[numscreen]);
  186.     return(RET_OK);
  187. } // do
  188.  
  189.  
  190. int SAVEDS mdofull(unsigned char *chunky,int numscreen) {
  191.     raswpx->BitMap=scrb[numscreen]->sb_BitMap;
  192.     WritePixelArray8(raswpx,0,0,SCRWIDTH-1,SCRHEIGHT-1,chunky,tmpraswpx);
  193.     ChangeScreenBuffer(scr,scrb[numscreen]);
  194.     return(RET_OK);
  195. } // dofull
  196.  
  197.  
  198. int SAVEDS mdont(void) {
  199.     return(RET_OK);
  200. } // dont
  201.  
  202.  
  203. void SAVEDS msleep(void) {
  204.     if(win) {
  205.         InitRequester(&InvisibleRequester);
  206.         Request(&InvisibleRequester,win);
  207.         SetWindowPointer(win,WA_BusyPointer,TRUE,TAG_DONE);
  208.         winsleeped=1;
  209.     }
  210. }
  211.  
  212.  
  213. void SAVEDS mawake(void) {
  214.     if(winsleeped) {
  215.         if(win) {
  216.             EndRequest(&InvisibleRequester,win);
  217.             SetWindowPointerA(win,NULL);
  218.             SetPointer(win,nopointer,1,16,0,0);
  219.             winsleeped=0;
  220.         }
  221.     }
  222. }
  223.